package main.java.message;

import java.io.DataOutputStream;
import java.net.Socket;

import main.java.regression.User;

public class MessageSender {
	private String ip;
	private int port;
	private Socket socket;

	public MessageSender(User user) {
		setIp(user.getIp());
		setPort(user.getPort());
	}

	public MessageSender(String ip, int port) {
		setIp(ip);
		setPort(port);
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void sendMessage(String msg) {
		try {
			socket = new Socket(ip, port);
			DataOutputStream os = new DataOutputStream(socket.getOutputStream());
			os.write(msg.getBytes());
			os.flush();
			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
